home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ivbsrc / prtinfo1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  4.7 KB  |  133 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Get default printer info"
  4.    ClientHeight    =   4515
  5.    ClientLeft      =   3540
  6.    ClientTop       =   1425
  7.    ClientWidth     =   3645
  8.    FontBold        =   -1  'True
  9.    FontItalic      =   0   'False
  10.    FontName        =   "MS Sans Serif"
  11.    FontSize        =   12
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   4920
  15.    Left            =   3480
  16.    LinkMode        =   1  'Source
  17.    LinkTopic       =   "Form1"
  18.    ScaleHeight     =   4515
  19.    ScaleWidth      =   3645
  20.    Top             =   1080
  21.    Width           =   3765
  22.    WindowState     =   1  'Minimized
  23.    Begin CommandButton Command2 
  24.       Caption         =   "End"
  25.       Height          =   255
  26.       Left            =   2400
  27.       TabIndex        =   3
  28.       Top             =   3240
  29.       Width           =   615
  30.    End
  31.    Begin CommandButton Command1 
  32.       Caption         =   "Get Default Printer Info"
  33.       Height          =   255
  34.       Left            =   120
  35.       TabIndex        =   0
  36.       Top             =   3240
  37.       Width           =   2295
  38.    End
  39.    Begin Label lblLPI 
  40.       BorderStyle     =   1  'Fixed Single
  41.       Caption         =   "Label1"
  42.       Height          =   255
  43.       Left            =   120
  44.       TabIndex        =   5
  45.       Top             =   1920
  46.       Width           =   3375
  47.    End
  48.    Begin Label lblPort 
  49.       Height          =   255
  50.       Left            =   240
  51.       TabIndex        =   2
  52.       Top             =   960
  53.       Width           =   3135
  54.    End
  55.    Begin Label lblDriver 
  56.       Height          =   255
  57.       Left            =   240
  58.       TabIndex        =   1
  59.       Top             =   600
  60.       Width           =   3135
  61.    End
  62.    Begin Label lblPrinter 
  63.       Height          =   255
  64.       Left            =   240
  65.       TabIndex        =   4
  66.       Top             =   240
  67.       Width           =   3135
  68.    End
  69. Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer
  70. Dim PageScale As POINTAPI, PageSize As POINTAPI
  71. Sub Command1_Click ()
  72.   lpAppName$ = "windows"
  73.   lpKeyName$ = "device"
  74.   nSize% = 81
  75.   lpRetStr$ = Space$(nSize%)
  76.   NumChars% = GetProfileString(lpAppName$, lpKeyName$, NullStr$, lpRetStr$, nSize%)
  77.   koRetStr$ = Left$(lpRetStr$, NumChars%)
  78.   CommaPos1% = InStr(1, lpRetStr$, ",")
  79.   CommaPos2% = InStr(CommaPos1% + 1, lpRetStr$, ",")
  80.   lblPrinter.Caption = "Printer: " + Left$(lpRetStr$, CommaPos1% - 1)
  81.   lblDriver.Caption = "Driver: " + Mid$(lpRetStr$, CommaPos1% + 1, CommaPos2% - CommaPos1% - 1) + ".DRV"
  82.   lblPort.Caption = "Port: " + Mid$(lpRetStr$, CommaPos2% + 1)
  83.     Result% = Escape(Printer.hDC, GETPHYSPAGESIZE, NULL, NULL, PageSize)
  84.     Orientation% = Escape(Printer.hDC, GETSETPRINTORIENT, 0, NULL, NULL)
  85.     Result% = DeviceInfo%()
  86.     Select Case Orientation%
  87.       Case 1
  88.     '    lblOrientation.Caption = "Orientation: Portrait"
  89.         X_Size! = PageSize.X / PageScale.X
  90.         Y_Size! = PageSize.Y / PageScale.Y
  91.         Vertical_resolution = PageScale.Y
  92.       Case 2
  93.     '    lblOrientation.Caption = "Orientation: Landscape"
  94.         Y_Size! = PageSize.X / PageScale.X
  95.         X_Size! = PageSize.Y / PageScale.Y
  96.         Vertical_resolution = PageScale.X
  97.       Case Else
  98.     '    lblOrientation.Caption = ""
  99.     End Select
  100.     If X_Size > 0 And Y_Size > 0 Then
  101.       Page_Size$ = Str$(X_Size!) + " x" + Str$(Y_Size!)
  102.     '  lblPaperSize.Caption = "Page Size:" + Page_Size$ + " inches"
  103.     Else
  104.     '  lblPaperSize.Caption = ""
  105.     End If
  106.     'lblXSize.Caption = "X Size = " + Str$(X_Size!)
  107.     'lblYSize.Caption = "Y Size = " + Str$(Y_Size!)
  108.     'lblVerticalResolution.Caption = "Vertical Resolution = " + Str$(Vertical_resolution)
  109.     Result% = DeviceInfo%()
  110.     'lblScaleX.Caption = "Pixels X: " + Str$(PageScale.X)
  111.     'lblScaleY.Caption = "Pixels Y: " + Str$(PageScale.Y)
  112.     LPI% = Lines_Per_Inch(Int(PageScale.Y))
  113.   lblLPI.Caption = Str$(LPI%)
  114. End Sub
  115. Sub Command2_Click ()
  116.   End
  117. End Sub
  118. Function DeviceInfo () As Integer
  119.   On Error GoTo Device_Error
  120.   DeviceInfo = True
  121.   PageScale.X = GetDeviceCaps(Printer.hDC, LOGPIXELSX)
  122.   PageScale.Y = GetDeviceCaps(Printer.hDC, LOGPIXELSY)
  123.   Exit Function
  124. Device_Error:
  125.   DeviceInfo = False
  126.   Exit Function
  127. End Function
  128. Function Lines_Per_Inch (Pixels_Per_Inch As Integer) As Single
  129.   Dim TextMetrix As TEXTMETRIC
  130.   Result% = GetTextMetrics(Printer.hDC, TextMetrix)
  131.   Lines_Per_Inch = Pixels_Per_Inch / (TextMetrix.tmHeight + TextMetrix.tmExternalLeading)
  132. End Function
  133.